package com.gxa.controller;

import com.gxa.pojo.Attentionp;
import com.gxa.service.AttentionpService;
import com.gxa.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * User: bear
 * Date: 2020/09/25
 * Description
 * Version: V1.0
 */
@Controller
@RequestMapping("/attentionpController")
@Transactional
public class AttentionpController {
    @Resource
    AttentionpService attentionpService;
    JsonResult jsonResult = new JsonResult();
    Attentionp attentionp = new Attentionp();

    /**
     * 添加患者关注医生
     *
     * @param map 患者id和医生id
     * @return 返回添加信息
     */
    @PostMapping("/add")
    @ResponseBody
    public Map add(@RequestBody Map<String, Integer> map) {
        try {
            attentionp.setPatientId(map.get("patientId"));
            attentionp.setDoctorId(map.get("doctorId"));
            attentionpService.add(attentionp);
            jsonResult.setCode("200");
            jsonResult.setMsg("添加成功");

        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setCode("500");
            jsonResult.setMsg("添加失败，系统出小差了");
        }
        return jsonResult.getValues();
    }

    /**
     * 患者关注的所有医生
     * @param map   患者id
     * @return  返回患者关注的所有医生
     */
    @PostMapping("/findByPatientId")
    @ResponseBody
    public Map findByPatientId(@RequestBody Map<String, Integer> map) {
        try {
            List<Attentionp> patientId = attentionpService.findByPatientId(map.get("patientId"));
            jsonResult.setData(patientId);
            jsonResult.setCode("200");
            jsonResult.setMsg("关注的所有医生");
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setCode("500");
            jsonResult.setMsg("系统开小差了");
        }

        return jsonResult.getValues();
    }
}
